package com.adcc.pushXml.server;

import com.adcc.pushXml.core.FlightPos;
import com.adcc.pushXml.utils.ParseMsg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * @author LHB
 * @date 2019/11/22 16:56
 */
@Component
public class ExecuteParseMsg {
    private Logger log = LoggerFactory.getLogger(ExecuteParseMsg.class);

    @Autowired
    private SendUdp sendUdpl;


    /*
     * 将解析任务加入线程池
     */
    @Async(value = "threadPoolTaskExecutor")
    public void parseXmlByMsg(FlightPos flight) {
        try {
            //发送端口 50000
            String resultXml = ParseMsg.getPort500XML(flight);
            if (StringUtils.isEmpty(resultXml)) {
                sendUdpl.sendUdp1(resultXml);
            }

        } catch (Exception e) {
            log.error("parseXmlByMsg sendUdp 50000", e);
        }

        try {
            //发送端口 50001
            String resultXml2 = ParseMsg.getPort501XmlMode(flight);
            if (StringUtils.isEmpty(resultXml2)) {
                sendUdpl.sendUdp2(resultXml2);
            }
        } catch (Exception e) {
            log.error("parseXmlByMsg sendUdp 50001", e);
        }
    }


}
